/*
 * Copyright (C) 2009 Rob Cash
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * MessageStoreFactory.java
 * 
 * Created on Jan 14, 2009 at 4:07:58 PM
 */

package org.robcash.apps.messagepopup.vo;

import org.robcash.apps.messagepopup.vo.impl.LocalFileMessageStore;
import org.robcash.apps.messagepopup.vo.impl.LocalFileMessageStoreLocation;
import org.robcash.apps.messagepopup.vo.impl.RemoteFileMessageStore;
import org.robcash.apps.messagepopup.vo.impl.RemoteFileMessageStoreLocation;

/**
 *
 * @author Rob
 */
public class MessageStoreFactory {

    /**
     * Only the static newInstance method can create new factories
     */
    protected MessageStoreFactory() {}
    
    /**
     * Get a new message store factory
     * @return message store factory
     */
    public static MessageStoreFactory newInstance() {
        return new MessageStoreFactory();
    }

    /**
     * Create a new message store
     * @param location Location of message store
     * @return New message store
     * @throws IllegalArgumentException Thrown if the location type is not
     * supported - Always thrown
     */
    public MessageStore newMessageStore(MessageStoreLocation location)
            throws IllegalArgumentException {
        if ( location instanceof LocalFileMessageStoreLocation ) {
            return new LocalFileMessageStore(
                    (LocalFileMessageStoreLocation) location);
        }
        else if ( location instanceof RemoteFileMessageStoreLocation ) {
            return new RemoteFileMessageStore(
                    (RemoteFileMessageStoreLocation) location);
        }
        throw new IllegalArgumentException("Specified location is not supported");
    }

}
